var left = document.getElementsByClassName('jiantou_left')
var right = document.getElementsByClassName('jiantou_right')
//默认当前图片索引
var img_index = 0;
//获取图片组
var ul_one = document.getElementsByClassName('one')
//获取轮播点组
var ul_twe = document.getElementsByClassName('twe')

//默认选中
ul_twe[0].children[img_index].style = "background-color: #aaaaaa;"

for (var j = 0; j < ul_twe[0].children.length; j++) {
	ul_twe[0].children[j].setAttribute('index', j);
	ul_twe[0].children[j].onclick = function() {
		img_index = this.getAttribute('index') - 1;
		right[0].onclick()
	}
}

right[0].onclick = function() {
	// alert('右箭头')
	for (var i = 0; i < ul_one[0].children.length; i++) {
		ul_one[0].children[i].style = "display:none;"
	}
	for (var j = 0; j < ul_twe[0].children.length; j++) {
		ul_twe[0].children[j].style = "background-color: #000000;"
	}
	img_index++;
	ul_one[0].children[img_index].style = "display:block";
	ul_twe[0].children[img_index].style = "background-color: #aaaaaa;"
	// console.log(img_index);
	if (img_index >= ul_one[0].children.length - 1) {
		// console.log(img_index);
		img_index = -1;
	}
}


left[0].onclick = function() {
	// alert('左箭头')
	if (img_index == -1) {
		img_index = ul_one[0].children.length - 1
	}

	if (img_index == 0) {
		img_index = ul_one[0].children.length
	}

	//for循环：初始化所有的图片都是影藏的
	for (var i = 0; i < ul_one[0].children.length; i++) {
		ul_one[0].children[i].style = "display:none;"
	}
	for (var i = 0; i < ul_one[0].children.length; i++) {
		ul_twe[0].children[i].style = "background-color: #000000;"
	}
	img_index--;
	ul_one[0].children[img_index].style = "display:block";
	ul_twe[0].children[img_index].style = "background-color: #aaaaaa;"
	// console.log(img_index);
}
var time = window.setInterval(function() {
	right[0].onclick();
}, 3000)

var stop = document.getElementsByClassName('box')
stop[0].onmouseover = function() {
	clearInterval(time);
}
stop[0].onmouseout = function() {
	time = window.setInterval(function() {
		right[0].onclick();
	}, 3000)
}
